// examples/pull_image.go
// 拉取镜像示例

package examples

import (
	"context"
	"log"

	"github.com/onyx/snapshotter/pkg/config"
	"github.com/onyx/snapshotter/pkg/integration"
)

func ExamplePullImage() error {
	// 创建配置
	cfg := &config.Config{
		Root:            "/var/lib/onyx-snapshotter",
		GRPCAddress:     "unix:///run/onyx-snapshotter/snapshotter.sock",
		ChunkSize:       4 * 1024 * 1024,
		DBBackend:       "pebble",
		FanotifyEnabled: true,
		UblkEnabled:     true,
	}

	// 创建服务
	svc, err := integration.NewFullService(cfg)
	if err != nil {
		return err
	}
	defer svc.Stop(context.Background())

	// 启动服务
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
	defer cancel()

	if err := svc.Start(ctx); err != nil {
		return err
	}

	// 拉取镜像（lazy pull）
	if err := svc.PullImage(ctx, "docker.io/library/alpine:latest", true); err != nil {
		return err
	}

	// 获取并打印指标
	metrics := svc.GetMetrics()
	log.Printf("Metrics: %+v", metrics)

	return nil
}

// ---
